﻿using System;
using System.Web;
using System.Net.Mail;
using System.Web.UI;
using SimplePMT.Data;
using SimplePMT.Control;
using System.Text;
using System.Collections.Generic;
using Castle.ActiveRecord;
using NHibernate.Expression;
using SimplePMT.Components;

namespace SimplePMT
{
    public partial class AdminUserInfo : Components.BasePage
    {
        public string viewRendered = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(AdminUserInfo), this.Page);
            ValidateSession();
            Control.AdminUserInfoControl view = this.LoadControl("./Control/AdminUserInfoControl.ascx") as Control.AdminUserInfoControl;
            int memberId = 0;
            if (Request.QueryString["id"] != null)
            {
                memberId = Convert.ToInt32(Request.QueryString["id"]);
            }
            view.AdminAccess = AdminAccess;
            view.MemberID = memberId;
            viewRendered = view.ToString();
        }

        [AjaxPro.AjaxMethod()]
        public bool SaveChanges(int MemberID, string FirstName, string LastName, string Username, string Password, string EmailAddress, string ContactPhone, bool ShowInfo, bool Terminated, bool ReadOnly, bool AdminAcccess)
        {
            Member m = Member.Find(MemberID) ?? new Member();
            m.FirstName = FirstName;
            m.LastName = LastName;
            m.UserName = Username;
            m.Password = Password;
            m.EmailAddress = EmailAddress;
            m.ContactPhone = ContactPhone;
            m.Terminated = Terminated;
            if (m.ID.Equals(0))
            {
                m.JoinDateTime = DateTime.Now;
            }
            if (ShowInfo)
            {
                m.ShowEmailAddress = true;
                m.ShowFullName = true;
            }
            else
            {
                m.ShowFullName = false;
                m.ShowEmailAddress = false;
            }
            m.ReadOnly = ReadOnly;
            m.AdminAccess = AdminAcccess;
            m.Save();
            return true;
        }


    }
}
